package com.servlet;

import java.io.IOException;

import com.javabean.Student;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/update")
public class UpdateServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			req.setCharacterEncoding("utf-8");
			resp.setContentType("text/html;charset=utf-8");
			String no = req.getParameter("no");
			String name = req.getParameter("name");
			String age = req.getParameter("age");
			String sex = req.getParameter("sex");
			Student st = new Student();
			st.setNo(no);
			st.setName(name);
			st.setAge(Integer.parseInt(age));
			st.setSex(sex);
			Student.update(st);
			req.getRequestDispatcher("stu_list.jsp").forward(req, resp);
	}
		
}
